var api = require('../../utils/api.js');
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        alls:[]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        var that=this;
        api.post({
            url: 'index/getalluser',
            data: {},
            success: data => {
                var info = data.data;
                that.setData({
                    user: info
                })
            }
        })
    },
    onShow(){

        wx.setStorageSync('all', '');

        var alls= wx.getStorageSync('all');
        console.log(alls.length);
        if(alls.length>0){
            this.setData({
                alls:alls
            })
        }
    },

    xunze(ret){
        console.log(ret);
        var index=ret.currentTarget.dataset.index;
        var list=this.data.user;
        var sex= list[index].sex;
        if(sex){
            list[index].sex=0;
        }else{
            list[index].sex=1;
        }
        console.log(list);
        this.setData({
            user:list
        })

    },

    submits(){

        var list=this.data.user;

        var array=this.data.alls;
        console.log(array);

        list.forEach(item => {
            console.log(item);
            if(item.sex==1){
                array.push(item);
            }
        });

        console.log(array);

        wx.setStorageSync('all', array);
        wx.navigateBack({
          delta: 0,
        })

    }

    
})